package com.itheima.demo1;

import com.sun.org.apache.xpath.internal.SourceTree;

import java.util.EmptyStackException;
import java.util.Random;
import java.util.Scanner;

public class RandomTest {
    public static void main(String[] args) {
        //创建对象
        Random r = new Random();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个1到100之间的数字!");
         // 输入100 是指0-99之间的数字  +1 就是1到100之间的数字
        int num = r.nextInt(100)+1;

        while (true) {
            int shu = sc.nextInt();
            if (shu < 0 || shu > 100) {
                System.out.println("输入数字错误!请重新输入");
            } else if (num > shu) {
                System.out.println("猜小了");
            } else if (num < shu) {
                System.out.println("猜大了");
            } else {
                System.out.println("恭喜猜对了!");
                break ;
            }
        }

    }
}
